package info.techgeek.labs.StringConcatenation;

import info.techgeek.labs.String.StringSupplier;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class StringSplit {
	
	public static void main (String args[]) throws IOException{
		StringBuffer stringBuffer = new StringBuffer();
				
		System.out.println("Enter Sting");
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String string = br.readLine();
//		StringSupplier stringSupplier = new StringSupplier();
//		String string  = stringSupplier.getString();
		System.out.println("String length "+string.length());
		
		long t = System.currentTimeMillis(); 
		StringSplit getS = new StringSplit();
		List<String> list = (ArrayList<String>) getS.getSuffix(string);
		System.out.println("---------------------------------------------------");
		for(String string2 : list){
			System.out.println("String "+string2);
		}
		System.out.println("Time Taken For My Logic :" +( System.currentTimeMillis() -t));
	}
	
	private List<String> getSuffix(String openString){
		
	 	System.out.println("Begin getSuffix "+openString);
		String suffix = "";
		List<String> list = new ArrayList<String>(); 
		boolean startAppend = false;
		for(int i = 0;i<openString.length();i++){
			System.out.println("Inside For Loop ");
			char character =  openString.charAt(i);
			System.out.println("Character "+character);
			if(startAppend){
				System.out.println("Inside Start Append ");
				if(",".equals(String.valueOf(character)) || " ".equals(String.valueOf(character))  
						|| "|".equals(String.valueOf(character))){
					System.out.println("Inside If the Check of , Space");
//					List<IiParam> paramList = (ArrayList<IiParam>)navigationDao.getParamType(suffix);
					System.out.println("suffix "+suffix);
					list.add(suffix);
					suffix = "";
					startAppend = false;
				}else{
					suffix += character;
					System.out.println("Inside Else "+suffix);
				}
			}
			if("&".equals(String.valueOf(character))){
				System.out.println("Inside & Check "+suffix+" "+character);
				if(suffix.equals(String.valueOf(character))){
					suffix = "";
					startAppend = false;
				}else{
					startAppend = true;
				}
			}
		}
		if(!suffix.equals("")){
			list.add(suffix);
		}
		System.out.println("End getSuffix "+list.size());
		return list;
 }
}
